<?php

/**
 * @author ThanhKhoaIT
 * @copyright 2013
 */

include_once("/owl/database/ntk/All.php");

class Config
{
    public $Name;
    public $Value;
    
    private $tablename = "ntk_config";
    private $columns = "name,value";
    
    protected function Get_($row)
    {
        $this->Name = $row["name"];
        $this->Value = $row["value"];
    }
    
    protected function Set_()
    {
        $col = $this->Col_();
        $col['name'] = $this->Name;
        $col['value'] = $this->Value;
        return $col;
    }
    
    protected function Where_($value)
    {
        return " Where name = '$value' ";
    }
    
    protected function Col_()
    {
        $tmp = explode(",", $this->columns);
        $col = array();
        for ($i = 0; $i<count($tmp); $i++)
        {$col[$tmp[$i]] = "";}
        return $col;
    }
    
    function Get($id)
    {       
        $col = $this->Col_();
        $data = DB::select($this->tablename, $col, $this->Where_($id), "");
        if ($data != null)
        {
            $row = mysqli_fetch_array($data);
            $this->Get_($row);
        }
    }
    
    function Update()
    {
        $col = $this->Set_();
        DB::update($this->tablename, $col, $this->Where_($this->Name));
    }
    
    function Insert()
    {
        $col = $this->Set_();
        DB::insert($this->tablename, $col);
    }
}
?>